
package kaizone.haining.chaobohui.net;

import java.io.InputStream;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import android.util.Log;

public class Request {

    public final static String TAG = "Request";

    public static InputStream getHttpInputStream(String url, Listener listener) throws Exception {
        HttpGet request = new HttpGet(url);
        HttpClient client = new DefaultHttpClient();
        InputStream in = null;
        HttpResponse response = null;
        response = client.execute(request);
        if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
            HttpEntity entity = response.getEntity();
            // Log.e(TAG, entity.toString());
            if (listener != null) {
                listener.onComplete();
            }
            in = entity.getContent();
            return in;
        } else {
            if (listener != null) {
                listener.onFaile();
            }
        }
        return null;
    }

    public interface Listener {
        void onStart();

        void onComplete();

        void onExeception(String exception);

        void onFaile();
    }

}
